<script type="text/javascript">
	$(document).ready(function(){			
		
		$("select").chosen();
		
		$(".various").fancybox({
			maxWidth	: 960,
			maxHeight	: 600,
			fitToView	: false,
			width		: '100%',
			height		: '70%',
			autoSize	: false,
			closeClick	: false,
			openEffect	: 'none',
			closeEffect	: 'none'
		});		
		
		$(".remove-image").live('click',function(e){
			var data = {'filename':'','table':'<?php echo $table; ?>','id':'<?php echo isset($id)?$id:'';?>','fieldname':$("#picture-field").val()};
			$.ajax({
				type:'post',
				url:base_url+'admin/attach_file',
				data:data,
				dataType:'json',
				success:function(ret)
				{
					document.location='';
				}
			});
		});
		
		$("#update-table").live('click',function(e){			
			var text = $("#update-table").html();
			$("#update-table").html(loader);			
			var data = {};
			$('.postvar').each(function(){
				data[$(this).attr('name')] = $(this).val();
			});						
			
			$.ajax({
				type:'post',
				url:'<?php echo base_url() ?>admin/update_table/<?php echo $table; ?>',
				data:data,
				dataType:'json',
				success:function(data){
					$("#message").html(data.message);
					$("#message").fadeIn('slow');
					$("#update-table").html(text);					
					if(data.message == 'success' && data.redirect!='')
						document.location=data.redirect;
				}
			});
		});
		
		$(".delete-modal").on('click',function(e){
			$("#picture-field").val($(this).attr('rel'));			
		});

	});
	
	
</script>